home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7149 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointers to Linked Lists
  5. Date: Sat, 17 Feb 96 22:59:30 GMT
  6. Organization: none
  7. Message-ID: <824597970snz@genesis.demon.co.uk>
  8. References: <4fjs0b$7sb@texas.nwlink.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4fjs0b$7sb@texas.nwlink.com> jlim@nwlink.com "John Lim" writes:
  15.  
  16. >please help me with this pointer question
  17. >
  18. >
  19. >typedef struct node
  20. >{
  21. >   generic_ptr  data;           (generic_ptr is a pointer to void)
  22. >   struct node  *next;
  23. >} node, *list;
  24. >
  25. >so i know that list is a pointer to a node
  26. >
  27. >in main i have the lines
  28. >
  29. >list    pairlist;
  30. >
  31. >adtInitializeList (&pair_list)          (adtInitializeList is a library
  32.  
  33. Make that:
  34.  
  35.  adtInitializeList (&pairlist);
  36.  
  37. >in libadt.c
  38. >
  39. >adtInitializeList (list *pL)
  40. >{
  41. >   *pL=NULL;
  42. >   return OK:
  43. >}
  44. >
  45. >so my questions are:
  46. >- isn't pL a pointer to a pointer to a node?  because it is of type
  47. >list and list is a pointer to a node
  48.  
  49. Yes, it is.
  50.  
  51. >-if so why would one need to use this?  why can't you just use 
  52. >adtInitializeList (list pL)?
  53.  
  54. You can unless adtInitializeList() needs to modify the node pointer i.e.
  55. pairlist in main() in this case. Function arguments are passed by value
  56. hence in line with the 2nd version a call of:
  57.  
  58.    adtInitializeList (pairlist);
  59.  
  60. a copy of the value of pairlist is passed to adtInitializeList() but that
  61. function can't change the value of pairlist itself.
  62.  
  63. -- 
  64. -----------------------------------------
  65. Lawrence Kirby | fred@genesis.demon.co.uk
  66. Wilts, England | 70734.126@compuserve.com
  67. -----------------------------------------
  68.